package com.xinqi.modules.user.user.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.user.user.client.UserClient;
import com.xinqi.modules.user.user.dto.req.*;
import com.xinqi.modules.user.user.dto.rsp.SearchFriendResultDTO;
import com.xinqi.modules.user.user.dto.rsp.UserBaseInfoDO;
import com.xinqi.modules.user.user.dto.rsp.UserPasswordResultDTO;
import com.xinqi.modules.user.user.dto.rsp.UserResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户表降级处理
 *
 * @author: system
 * @date: 2023/01/17
 */
@Slf4j
@Component
public class UserFallbackFactory implements FallbackFactory<UserClient> {

    @Override
    public UserClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new UserClient() {

            @Override
            public R<List<SearchFriendResultDTO>> search(SearchFriendDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<List<UserResultDTO>> list(UserQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserPasswordResultDTO> findPasswordById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<List<UserResultDTO>> findList(List<Long> userIds) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<List<UserResultDTO>> findByMobile(List<String> mobileList) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> findByMobile(String mobile) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<List<UserBaseInfoDO>> getUserBaseInfoContainDelByMobile(String mobile) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> findImitateByMobileAndNickname(String mobile, String nickname) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserBaseInfoDO> getUserBaseInfo(Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> register(UserRegisterDTO register) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> accountBan(List<Long> userIds) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> accountUnblocking(List<Long> userIds) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> findByMobileIncludeDelete(String mobile) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> registerAssistant() {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> imitateUser(UserImitateDTO dt) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> imitateUserUpdate(UserImitateUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<UserResultDTO> getInfo(Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
